package com.dragon.graduation.projectProgress.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.graduation.projectProgress.controller.dto.ProjectProgressSearchDTO;
import com.dragon.graduation.projectProgress.controller.vo.ProjectProgressVO;
import com.dragon.graduation.projectProgress.entity.ProjectProgressEntity;
import com.dragon.graduation.projectProgress.mapper.ProjectProgressMapper;
import com.dragon.graduation.projectProgress.service.ProjectProgressService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 毕设进度表 服务实现类
 * </p>
 *
 * @author dragon
 * @since 2025-02-28 21:20:30
 */
@Service
public class ProjectProgressServiceImpl extends ServiceImpl<ProjectProgressMapper, ProjectProgressEntity> implements ProjectProgressService {

    @Override
    public Page<ProjectProgressVO> findPages(Page<ProjectProgressEntity> entityPage, ProjectProgressSearchDTO searchDTO) {
        return baseMapper.selectPages(entityPage, searchDTO);
    }

    @Override
    public void record(Integer studentId, Integer projectId, int type, int status) {
        ProjectProgressEntity projectProgress = baseMapper.selectByProjectIdAndStudentId(projectId, studentId);
        if (ObjectUtils.isEmpty(projectProgress)) {
            projectProgress = ProjectProgressEntity.builder()
                    .projectId(projectId)
                    .studentId(studentId)
                    .selectionPassed(-1)
                    .proposalPassed(-1)
                    .midtermPassed(-1)
                    .finalPassed(-1)
                    .graduationPassed(-1)
                    .build();
            baseMapper.insert(projectProgress);
        }
        switch (type) {
            case 1:
                //选题申请
                projectProgress.setSelectionPassed(status);
                break;
            case 2:
                //开题报告
                projectProgress.setProposalPassed(status);
                break;
            case 3:
                //中期答辩
                projectProgress.setMidtermPassed(status);
                break;
            case 4:
                //终期答辩
                projectProgress.setFinalPassed(status);
                break;
            case 5:
                //毕业材料
                projectProgress.setGraduationPassed(status);
                break;
        }
        baseMapper.updateById(projectProgress);
    }

    @Override
    public ProjectProgressEntity findByProjectIdAndStudentId(Integer projectId, Integer roleId) {
        return baseMapper.selectByProjectIdAndStudentId(projectId, roleId);
    }
}
